import React from 'react';
import { Row, Input,Button } from 'antd';
import './login.css'
import Ontrial from './Ontrial'
import {login,WXloginUrl} from '../../redux/login/login'
import { connect } from 'react-redux'
import {withRouter } from 'react-router-dom'
import WXLogin from './WXLogin'
@withRouter
@connect(
    state => state,
    { login, WXloginUrl}
)
export default class PassWord extends React.Component{
    constructor(){
        super();
        this.state = {
            visible : false
        }
    }
    componentWillReceiveProps(){
        if(this.props.userLogin.res){
            // this.props.history.push('/menuList')
        }else{
        }
    }
    ontrial(){
        this.setState({
            visible:!this.state.visible
        })
    }
    onLogin(){
        let iPhone = document.getElementById('iPhone').value
        let password = document.getElementById('password').value
        console.log(!this.props.userLogin.code)
        if(this.props.userLogin.code === undefined || this.props.userLogin.code === '' || !this.props.userLogin.code){
            this.props.login(iPhone,password)
        }else{
            this.props.WXloginUrl(iPhone,password)
        }
       
    }
    wxLogin(){
        this.setState({
            visible:true
        })
    }
    showModel(){
        this.setState({
            visible:!this.state.visible
        })
    }
    fPassword(){
        this.props.history.push('/login/2')
    }
    register(){
        this.props.register("2");
    }
    render() {
        return (
            <div className='passWordList'>
                 <div >
                    <Input id='iPhone' className='iPhone' style={{height:'40px'}} placeholder="手机号" />
                    <Input id='password' className='password' style={{height:'40px'}} placeholder="登录密码" />
                    <Button className='btnPrimary' onClick={this.onLogin.bind(this)} style={{height:'40px'}} type="primary" block>立即登录</Button>
                    <Button className='btnblock' style={{height:'40px'}} onClick={this.wxLogin.bind(this)}  block>微信登陆</Button>
                    <div className='forgetList'>
                         <div className='Forget' onClick={this.fPassword.bind(this)}>忘记密码</div>
                         <div className='Forget1' onClick={this.register.bind(this)}>立即注册</div> 
                    </div>
                 </div>
                 <WXLogin visible = {this.state.visible} showModel = {this.showModel.bind(this)}/>

            </div>
            
        )
    }
}